<?php
	require_once('PageBase.php');
	require_once('DataAccess/Adapter/MailAdapter.php');
	require_once('DataAccess/DataModel/MailData.php');

class MailingList extends PageBase
{
	private static $maxRow = 10;
	
	public function __construct()
	{
		parent::__construct();

	}	


	public function pageLoad()
	{
		$preFlag = "TRUE";
		$nextFlag = "TRUE";
		$preRow = 0;
		$nextRow = 0;
		$rowNumber = 0;
		if($this->params["rownum"] == null)
		{
			$rowNumber = 0;
		}
		else
		{
			$rowNumber = $this->params["rownum"];
		}

		$mailAdapter =& new MailAdapter();
		$selectString = "select count(*) rowcount From mails where 0=0 ";
		$params[MailAdapter::$MAILTYPE] =& new Parameter(MailAdapter::$MAILTYPE,
												Parameter::$NUMBER_TYPE,
												MLCOM_MAIL_TYPE_MLIST);
		$params[MailAdapter::$MAILSTATUS] =& new Parameter(MailAdapter::$MAILSTATUS,
												Parameter::$NUMBER_TYPE,
												MLCOM_MAIL_STATUS_SENT);
		$mailAdapter->setSelectStringString($selectString, $params);
		$mailingList = $mailAdapter->select($params);
		if($mailingList[0][rowcount] <= MailingList::$maxRow)
		{
			$preFlag = "FALSE";
			$nextFlag = "FALSE";
		}
		else if($rowNumber == 0)
		{
			$preFlag = "FALSE";
			$nextFlag = "TRUE";
			$nextRow = $rowNumber + MailingList::$maxRow;
		}
		else if($rowNumber + MailingList::$maxRow >= $mailingList[0][rowcount])
		{
			$preFlag = "TRUE";
			$nextFlag = "FALSE";
			$preRow = $rowNumber - MailingList::$maxRow;
		}
		else
		{
			$preFlag = "TRUE";
			$nextFlag = "TRUE";
			$preRow = $rowNumber - MailingList::$maxRow;
			$nextRow = $rowNumber + MailingList::$maxRow;
		}
		$mailAdapter->setStartRow($rowNumber);
		$mailAdapter->setRowCount(MailingList::$maxRow);
		
		$mailAdapter->setSelectStringString(MailAdapter::$SELECT_STRING, $params);
		
		$mailingList = $mailAdapter->select($params);
		$this->smarty->assign("List", $mailingList);
		$this->smarty->assign("PreFlag", $preFlag);
		$this->smarty->assign("NextFlag", $nextFlag);
		$this->smarty->assign("PreRow", $preRow);
		$this->smarty->assign("NextRow", $nextRow);
		$this->smarty->display("MailingList.htpl");
	}
}	
	

?>